package com.own.business.wechat.mobile.entity.bo;

import com.own.business.wechat.mobile.entity.po.WechatMobileAuthentication;
import com.own.component.common.base.entity.BaseBo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * WechatMobileAuthenticationBo
 *
 * @author chenxueli
 * @date 2023-06-30 09:06:33
 */
@Schema(title = "微信移动应用认证" + ConstantBeanSuffix.BO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class WechatMobileAuthenticationBo extends BaseBo<WechatMobileAuthentication> implements Serializable {

    @Schema(title = "验证code")
    private String code;

    @Schema(title = "接口调用凭证")
    private String accessToken;

    @Schema(title = "access_token 接口调用凭证超时时间，单位（秒）")
    private Integer expiresIn;

    @Schema(title = "用户刷新 access_token")
    private String refreshToken;

    @Schema(title = "授权用户唯一标识")
    private String openId;

    @Schema(title = "用户授权的作用域，使用逗号（,）分隔")
    private String scope;

    @Schema(title = "用户统一标识。针对一个微信开放平台帐号下的应用，同一用户的 unionid 是唯一的")
    private String unionId;

    /**
     * 转持久化对象
     *
     * @param entity 原持久化对象
     * @return 持久化对象
     */
    @Override
    public WechatMobileAuthentication toPo(WechatMobileAuthentication entity) {
        if (entity == null) {
            entity = new WechatMobileAuthentication();
        }
        entity.setCode(this.code);
        entity.setAccessToken(this.accessToken);
        entity.setExpiresIn(this.expiresIn);
        entity.setRefreshToken(this.refreshToken);
        entity.setOpenId(this.openId);
        entity.setScope(this.scope);
        entity.setUnionId(this.unionId);
        return super.toPo(entity);
    }

}

